package com.wchat.network.device;

import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;

import com.wchat.network.message.Message;
import com.wchat.network.message.MessageSender;

public abstract class AbstractSendTarget implements SendTarget, Serializable {

	private static final long serialVersionUID = 4175152782311127889L;
	
	protected InetAddress address;
	
	public AbstractSendTarget(InetAddress address) {
		super();
		this.address = address;
	}

	@Override
	public void sendMessage(Message message) throws IOException {
		MessageSender.send(this, message);
	}

	@Override
	public InetAddress getAddress() {
		return address;
	}

	public void setAddress(InetAddress address) {
		this.address = address;
	}
	
	public boolean equals(Object o)
	{
		if(o==null || !(o instanceof SendTarget))
			return false;
		
		SendTarget target = (SendTarget)o;
		if(target.getAddress().equals(getAddress()))
			return true;
		
		return false;
	}
	

}
